package com.example.composableexample

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowRight
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

/**
 * author: LiLiang
 * createTime: 2022/9/24-17:39
 * remark:
 **/

@Preview
@Composable
fun ExpandedItemPreview() {

    var isShowChildItem by remember {
        mutableStateOf(false)
    }
    val rotateDegrees by animateFloatAsState(targetValue = if (isShowChildItem) 90F else 0F)

    Column {


        Row(
            modifier = Modifier
                .fillMaxWidth()
                .clickable { isShowChildItem = !isShowChildItem },
            verticalAlignment = Alignment.CenterVertically
        ) {
            Icon(
                imageVector = Icons.Default.KeyboardArrowRight,
                contentDescription = "",
                modifier = Modifier.rotate(rotateDegrees)
            )
            Text(text = "一级菜单")
        }
        AnimatedVisibility(visible = isShowChildItem, modifier = Modifier.padding(start = 24.dp)) {
            Column {
                Text(
                    text = "我是子内容1"
                )
                Text(
                    text = "我是子内容2"
                )
                Text(
                    text = "我是子内容3"
                )
            }
        }
    }

}